package com.song.controller.user;

import com.song.constant.StatusConstant;
import com.song.entity.Setmeal;
import com.song.result.Result;
import com.song.service.SetmealService;
import com.song.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("user-SetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
   private SetmealService setmealService;
    //根据分类id查询套餐
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    @GetMapping("/list")
    public Result<List<Setmeal>> getSetmealList(Long CategoryId) {
        log.info("查询的套餐数据:{}", CategoryId);
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(CategoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
        List<Setmeal> setmealList = setmealService.getSetmealList(setmeal);
        return Result.success(setmealList,"分类查询套餐成功" );
    }

    //根据套餐id查询包含的菜品
    @Cacheable(cacheNames = "setmeal_dishCache",key = "#id")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishItemById(@PathVariable Long id) {
        log.info("查询的套餐id为:{}", id);
        List<DishItemVO> list = setmealService.getDishItemBySetmealId(id);
        return Result.success(list,"套餐内的菜品查询成功");
    }
}
